package com.zhkj.txg.module.member.ui

import android.view.View
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayoutMediator
import com.zhkj.lib.base.BaseActivity
import com.zhkj.txg.R
import kotlinx.android.synthetic.main.activity_member_invite.*

class MemberInviteActivity : BaseActivity() {

    override fun statusTitleBar(): View? = titleMemberInvite
    override val layoutResId: Int = R.layout.activity_member_invite

    private val registerFragment: MemberInviteFragment by lazy {
        MemberInviteFragment.newInstance(0)
    }
    private val openFragment: MemberInviteFragment by lazy {
        MemberInviteFragment.newInstance(1)
    }

    override fun initUI() {
        with(vpMemberInvite) {
            getChildAt(0)?.overScrollMode = View.OVER_SCROLL_NEVER
            adapter = object : FragmentStateAdapter(this@MemberInviteActivity) {
                override fun getItemCount(): Int = 2

                override fun createFragment(position: Int): Fragment = when (position) {
                    0 -> registerFragment
                    else -> openFragment
                }
            }
        }

        TabLayoutMediator(tabMemberInvite, vpMemberInvite, TabLayoutMediator.TabConfigurationStrategy { tab, position ->
            when (position) {
                0 -> tab.customView = layoutInflater.inflate(R.layout.item_collect_goods, null).apply {
                    findViewById<TextView>(R.id.tvGoods).text = getString(R.string.register)
                }
                1 -> tab.customView = layoutInflater.inflate(R.layout.item_collect_goods, null).apply {
                    findViewById<TextView>(R.id.tvGoods).text = getString(R.string.register_and_open)
                }
            }
        }).attach()
    }
}